<template>
    <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" :visible.sync="visible">
    
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
    
            <el-form-item label="项目名称" prop="proId">
                <!-- <el-input v-model="dataForm.proId" placeholder="请输入项目id"></el-input> -->
                
                <el-select v-model="dataForm.proId" placeholder="请选择项目" style="width: 100%" clearable filterable>
                    <el-option
                    v-for="item in projectList"
                    :key="item.id"
                    :label="item.projectName"
                    :value="item.id">
                    </el-option>
                </el-select>
    
            </el-form-item>
    
            <el-form-item label="功能名称" prop="funcName">
    
                <el-input v-model="dataForm.funcName"  type="textarea" placeholder="请输入功能名称"></el-input>
    
            </el-form-item>

            <el-form-item label="功能描述" prop="funcDesc">
    
                <el-input v-model="dataForm.funcDesc"  type="textarea" placeholder="请输入功能描述"></el-input>

            </el-form-item>
            
            <el-row>
                <el-col :span="12">
                     <el-form-item label="开发状态" prop="funcIsComplete">
 
                        <el-radio-group v-model="dataForm.funcIsComplete">
    
                            <el-radio label="0">未开始</el-radio>
            
                            <el-radio label="1">进行中</el-radio>

                            <el-radio label="2">已完成</el-radio>
            
                        </el-radio-group>

                    </el-form-item>
                </el-col>
                <el-col :span="12">
                     <el-form-item label="测试状态" prop="testIsComplete">
    
                        <el-radio-group v-model="dataForm.testIsComplete">
    
                            <el-radio label="0">未开始</el-radio>
            
                            <el-radio label="1">进行中</el-radio>

                            <el-radio label="2">已完成</el-radio>
            
                        </el-radio-group>

                    </el-form-item>
                </el-col>
           </el-row>

           <el-row>
                <el-col :span="12">
                     <el-form-item label="进度" prop="processPercent">
 
                        <el-input-number v-model="dataForm.processPercent" :min="1" :max="100" label="请输入开发进度"></el-input-number>

                    </el-form-item>
                </el-col>
                <el-col :span="12">
                     <el-form-item label="开发周期" prop="devCycle">
    
                        <el-input-number v-model="dataForm.devCycle" :min="1" label="请输入开发周期"></el-input-number>

                    </el-form-item>
                </el-col>
           </el-row>

            <el-form-item label="测试问题" prop="testProblem">
    
                <el-input v-model="dataForm.testProblem"  type="textarea" placeholder="请输入测试问题"></el-input>

            </el-form-item>
    
        
    
            <!-- <el-form-item label="状态" size="mini" prop="status">
    
                <el-radio-group v-model="dataForm.status">
    
                    <el-radio :label="0">进行中</el-radio>
    
                    <el-radio :label="1">已完成</el-radio>
    
                </el-radio-group>
    
            </el-form-item> -->
    
        </el-form>
    
        <span slot="footer" class="dialog-footer">
    
          <el-button @click="visible = false">取消</el-button>
    
          <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    
        </span>
    
    </el-dialog>
</template>

<script>
import { isEmail, isMobile } from '@/utils/validate'
export default {
    data() {
        return {
            visible: false,
            projectList: [],
            dataForm: {
                id: 0,
                proId: null,
                projectName: '',
                funcName: '',
                funcDesc: '',
                devCycle: 1,
                processPercent: '',
                testProblem: '',
                testIsComplete: '0',
                funcIsComplete: '0'
            },
            dataRule: {
                projectName: [
                    { required: true, message: '项目名称不能为空', trigger: 'blur' }
                ]
            }
        }
    },
    created() {
        this.getProjectList()
    },
    methods: {
        init(id) {
            this.dataForm.id = id || 0
            this.visible = true
            this.$nextTick(() => {
                this.$refs['dataForm'].resetFields()
            })
            if (this.dataForm.id) {
                this.$http({
                    url: this.$http.adornUrl(`/project/func-test/info/${this.dataForm.id}`),
                    method: 'get',
                    params: this.$http.adornParams()
                }).then(({ data }) => {
                    if (data && data.code === 0) {
                      console.log('===>',data)
                      this.dataForm = {}
                        this.dataForm = data.funcTest
                    }
                })
            }



        },
        async getProjectList() {
            // 组装请求参数
			let requestParams = {
				url: this.$httpSdut.adornUrl('/project/plan/list-all'),
				method: 'get'
			}

			let {
				data
			} = await this.$httpSdut(requestParams);

            this.projectList = data.page
            console.log('===========>', this.projectList)
        },
        // 表单提交
        dataFormSubmit() {
            this.$refs['dataForm'].validate((valid) => {
                if (valid) {
                    this.$http({
                        url: this.$http.adornUrl(`/project/func-test/${!this.dataForm.id ? 'save' : 'update'}`),
                        method: 'post',
                        data: this.$http.adornData(this.dataForm)
                    }).then(({ data }) => {
                        if (data && data.code === 0) {
                            this.$message({
                                message: '操作成功',
                                type: 'success',
                                duration: 1500,
                                onClose: () => {
                                    this.visible = false
                                    this.$emit('refreshDataListEvent')
                                }
                            })
                        } else {
                            this.$message.error(data.msg)
                        }
                    })
                }
            })
        },
        resetForm() {
            this.dataForm = {
                id: 0,
                proId: null,
                projectName: '',
                funcName: '',
                funcDesc: '',
                devCycle: 1,
                processPercent: '',
                testProblem: '',
                testIsComplete: '0',
                funcIsComplete: '0'
            }
        }
    }
}
</script>
